using System.Collections.Generic;
using System.Data.SqlClient;
using BLL.Services.Comments.Listing;

namespace BLL.Services.Comments
{
    public class CommentsService : ICommentsService
    {
        private readonly CommentsCollection _commentsCollection;

        public CommentsService(CommentsCollection collection)
        {
            _commentsCollection = collection;
        }

        public Comment GetCommentById(int commentId)
        {
            try
            {
                return _commentsCollection.SelectById(commentId);
            }
            catch (SqlException sqlException)
            {
                throw new ServiceException(sqlException.Message);
            }
        }

        public void Create(Comment comments)
        {
            try
            {
                _commentsCollection.Create(comments);
            }
            catch (SqlException sqlException)
            {
                throw new ServiceException(sqlException.Message);
            }
        }

        public void Save(Comment comments)
        {
            try
            {
                _commentsCollection.Save(comments);
            }
            catch (SqlException sqlException)
            {
                throw new ServiceException(sqlException.Message);
            }
        }

        public void Delete(int commentId)
        {
            try
            {
                _commentsCollection.Delete(commentId);
            }
            catch (SqlException sqlException)
            {
                throw new ServiceException(sqlException.Message);
            }
        }

        public CommentsListing GetListingComments(int page, int size, string column, int direction, CommentFilter filter)
        {
            try
            {
                return _commentsCollection.GetListingComments(page, size, column, direction, filter);
            }
            catch (SqlException sqlException)
            {
                throw new ServiceException(sqlException.Message);
            }
        }
    }
}